/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pgpframework.authentication.key;

import java.io.File;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;

/**
 *
 * @author ufabc
 */
public class GeneratorKeyPair {

    public GeneratorKeyPair() {
    
    }
 
    public static KeyPair generate(String keyname)
    {
        KeyPair keyPair = null;
        try
		{
			File pubKeyFile = new File("/" + keyname + ".pubkey");
			File privKeyFile = new File("/" + keyname + ".privkey");
			
			KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
			
			
			kpg.initialize(1024);
			
			
			keyPair = kpg.genKeyPair();
			
			/*FileOutputStream publicFos = new FileOutputStream(pubKeyFile);
			publicFos.write(keyPair.getPublic().getEncoded());
			publicFos.close();
			
			
			FileOutputStream privFos = new FileOutputStream(privKeyFile);
			privFos.write(keyPair.getPrivate().getEncoded());
			privFos.close();
*/
		} catch (NoSuchAlgorithmException kpgNsae)
		{
			//Handle This!
			kpgNsae.printStackTrace();
		} catch (ArrayIndexOutOfBoundsException aioobe)
		{
		
		} /*catch (FileNotFoundException fnfe)
		{
			//Handle This!
			fnfe.printStackTrace();
		} catch (IOException ioe)
		{
			//Handle This!
			ioe.printStackTrace();
		}*/
        
        return  keyPair;
    }
}
